package ca.venasse.pinventory.part.query;

import org.axonframework.eventhandling.annotation.EventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ca.venasse.pinventory.part.event.PartCreatedEvent;
import ca.venasse.pinventory.part.query.repository.PartRepository;

@Repository
public class PartQueryUpdater {

	@Autowired
	private PartRepository partRepository;

	@EventHandler
	public void handle(PartCreatedEvent event) {
		PartEntity entity = new PartEntity(event.getAggregateIdentifier());
		entity.setCategory(event.getCategory());
		entity.setName(event.getName());

		this.partRepository.save(entity);
	}

}
